package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /*
    * 在数据库中查询是否有该菜品或套餐
    * */
    ShoppingCart list(ShoppingCart shoppingCart);

    /*
    * 根据菜品或者套餐id增加菜品或套餐数量
    * */
    void updateNumberById(ShoppingCart cart);

    /*
    * 添加购物车
    * */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)" +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /*
    * 根据用户id查看购物车
    * */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> selectAllByUserId(Long userId);

    /*
    * 根据菜品id和口味或者是套餐id删除商品
    * */
    void deleteByIdOrFlavor(ShoppingCart sc);

    /*
    * 清空购物车
    * */
    @Delete("truncate table shopping_cart ")
    void deleteAll();

}
